package cn.edu.zut.soft.student.controller.student;

import cn.edu.zut.soft.student.bean.ResultBean;
import cn.edu.zut.soft.student.model.Class;
import cn.edu.zut.soft.student.model.Notice;
import cn.edu.zut.soft.student.model.SelectCourse;
import cn.edu.zut.soft.student.model.Student;
import cn.edu.zut.soft.student.service.class_.ClassBo;
import cn.edu.zut.soft.student.service.class_.vo.ClassQuery;
import cn.edu.zut.soft.student.service.notice.NoticeBo;
import cn.edu.zut.soft.student.service.notice.vo.NoticeQuery;
import cn.edu.zut.soft.student.service.student.StudentBo;
import cn.edu.zut.soft.student.service.student.StudentSelectCoursesBo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @Author ChrisPhantom
 * @CreatDate 2021/02/23 19:52
 */
@RestController
@RequestMapping("/student/api")
public class StuController {
    @Autowired
    private NoticeBo noticeBo;
    @Autowired
    private StudentSelectCoursesBo sscb;
    @Autowired
    private StudentBo studentBo;
    @Autowired
    private ClassBo classBo;

    @PostMapping("/{studentid}")
    public ResultBean<Integer> updatePassword(@PathVariable("studentid") String studentid, String newpassword) {
        return new ResultBean<>(studentBo.resetPassword(studentid, newpassword));
    }

    @PutMapping("")
    public ResultBean<Integer> updateInfo(Student student) {
        return new ResultBean<>(studentBo.updateStudent(student));
    }

    @GetMapping("/notice")
    public ResultBean<List<Notice>> queryNotice() {
        NoticeQuery noticeQuery = new NoticeQuery();
        noticeQuery.setLimit(100);
        return new ResultBean<>(noticeBo.getNotices(noticeQuery));
    }

    @GetMapping("/class")
    public ResultBean<List<Class>> queryClasses(ClassQuery classQuery) {
        return new ResultBean<>(classBo.queryClasses(classQuery));
    }

    @GetMapping("/score/{courseid}")
    public ResultBean<SelectCourse> queryStudentSelectCourseScore(@PathVariable("courseid") String courseid, HttpSession session) {
        String studentid = (String) session.getAttribute("LoginUser");
        return new ResultBean<>(sscb.queryScore(studentid, courseid));
    }

    @GetMapping("/{studentid}")
    public ResultBean<Student> getInfo(@PathVariable("studentid") String studentid) {
        return new ResultBean<>(studentBo.queryStudentById(studentid));
    }
}
